package ai.zixing.mashibing.new_class.class02;

public class PreSum {

    public static void main(String[] args) {
        int[] arr = {1, 5, 3, -4};
        print(preSum(arr));
    }

    public static int[] preSum(int[] arr) {
        int len = arr.length;
        int[] preSum = new int[len];
        preSum[0] = arr[0];
        for (int i = 1; i < len; i++) {
            preSum[i] = preSum[i - 1] + arr[i];
        }
        return preSum;
    }

    public static void print(int[] arr) {
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
        System.out.println();
    }
}
